<template>
	<view class="content">
		<view class="itemcontent"  :style="'background-image:url('+ data.charge_image+'); background-size: 100% 100%;'">
		</view>
		<view class="list">
			<view @click="select(item.subject_name)" class="item" :class="{'select':selectarr.indexOf(item.subject_name)!=-1}" v-if="data.subject_num!=0" v-for="(item,index) in lists" :key="index">
				{{item.subject_name}}
			</view>
			<view class="item select" v-if="data.subject_num==0">
				全科
			</view>
		</view>
		<view class="bottom">
			<view class="agreerule" v-if="data.pad_cion!=0">
				<view class="agreerule_box" @tap="switchPad">
					<checkbox class="check" :checked="is_pad"/>
					<view class="pad">购买智学星Pad</view>
				</view>
			</view>
			<view class="bottom_item" v-if="is_pad">
				<view>金额</view>
				<view class="money">￥{{data.pad_cion}}</view>
			</view>
			<view class="bottom_item">
				<view>有效时间</view>
				<view>{{data.enddate}}</view>
			</view>
			<view class="bottom_item">
				<view>有效天数</view>
				<view>{{data.day_num}}天</view>
			</view>
			<view class="bottom_item" v-if="data.activity_start_time<date&&data.activity_end_time>date &&data.activity_day!=0" >
				<view>活动</view>
				<view class="activity">免费赠送{{data.activity_day}}天</view>
			</view>
			<view class="bottom_item" v-if="data.activity_start_time<date&&data.activity_end_time>date &&data.activity_cion!=0" >
				<view>活动</view>
				<view class="activity">优惠{{data.activity_cion}}元</view>
			</view>
			<view class="agreerule">
				<view class="agreerule_box" @tap="switchremind">
					<checkbox class="check" :checked="is_remind"/>
					<view class="remind">是否开启会员卡到期提示</view>
				</view>
			</view>
		</view>
		
	<view @click="gotoyeralist" class="btn" v-if="Childinfo['member_card_id'] == data['unid']">续费</view>
	<view @click="gotoyeralist" class="btn" v-else>立即抢购</view>
	</view>
</template>

<script>
	import util from '@/common/util.js'
	export default {
		data() {
			return {
				lists:[],
				selectindex:0,
				data:[],
				selectarr:[],
				is_pad:false,
				is_remind:false,
				date:0,
				Childinfo:uni.getStorageSync('currentChild'),
				enddate:''
			}
		},
		onLoad(e) {
			this.data=JSON.parse(decodeURIComponent(e.data));
			this.date = parseInt(+new Date()/1000);
			/* 计算会员卡有效日期 */
			var day_all_num= this.data.day_num;
			if(this.data.activity_start_time<this.date&&this.data.activity_end_time>this.date &&this.data.activity_day!=0){
				day_all_num = day_all_num+ this.data.activity_day;
			}
			var endtime=this.date + day_all_num*86400;
			/* 会员卡续费进行计算 */
			if(this.Childinfo['member_card_id'] == this.data['unid']){
				endtime=this.Childinfo['closing_date'] + day_all_num*86400;
			}
			/* 会员卡续费进行计算 */
			this.data['enddate']=util.getLeftTime(endtime);
			/* 计算会员卡有效日期 */
			
			this.$zapi.apiPost('user/subject.Lists/subjectLists',{student_id:this.Childinfo.student_id})
				.then(res => {
					var data = res.data;
					if(data.code==200){
						this.lists=data.data;
					}
					else{
						uni.showToast({
							title: data.msg,
							icon:'none'
						});
					}
				});
		},
		methods:{
			switchPad:function(){
				this.is_pad= !this.is_pad;
			},
			switchremind:function(){
				this.is_remind= !this.is_remind;
			},
			select:function(subject_name){
				if(this.selectarr.indexOf(subject_name)!=-1){
					this.selectarr.splice(this.selectarr.indexOf(subject_name),1)
				}else{
				if(this.selectarr.length>=this.data.subject_num){
					uni.showToast({
						title: "选择科目数上限",
						icon:'none'
					});
				}else{
					this.selectarr.push(subject_name);
				}
				}
			},
			gotoyeralist:function(){
				if(this.data.subject_num!=0&&this.selectarr.length==0){
					uni.showToast({
						title: '请选择一个科目',
						icon:'none'
					});
				}else{
					if(this.selectarr.length>0){
						this.data.subject=this.selectarr;
					}
					this.data['is_pad']    = this.is_pad;
					this.data['is_remind'] = this.is_remind;
					uni.navigateTo({
						url:'pay?data='+encodeURIComponent(JSON.stringify(this.data))
					})
				}
			}
		}
		
	}
</script>

<style lang="scss">
	.content {
		width: 100%;
		height: 100%;
		position: absolute;
	}
	.itemcontent {
		width: 622upx;
		margin: auto;
		margin-top: 20upx;
		height: 318upx;
		border-radius: 20upx;
	}
	.list {
		width: 92%;
		margin: auto;
		display: flex;
		justify-content: flex-start;
		flex-wrap: wrap;

		.item {
			margin-top: 20upx;
			width: 214upx;
			height: 80upx;
			border-radius: 8upx;
			background: rgba(247, 247, 247, 1);
			text-align: center;
			line-height: 80upx;
			color: #666666;
			margin-right: 20upx;
		}
	}
	.item:nth-child(3n) {
		margin-right: 0upx !important;
	}
	.select{
		background:#FF9900 !important;
		color: #fff !important;
	}
	.btn{
		width: 92%;
		height: 80upx;
		border-radius:4px;
		background:#FF9900;
		text-align: center;
		line-height: 80upx;
		font-size: 34upx;
		color: #FFFFFF;
		position: fixed;
		left: 4%;
		bottom: 30upx;
		}
		
		.bottom{
			width: 92%;
			margin: auto;
		}
		
		.agreerule{
			display: flex;
			justify-content: flex-end;
			color: #adadad;
			padding: 10upx auto;
			font-size: 32upx;
			margin-top: 10upx;
			.agreerule_box{
				display: flex;
				align-items: center;
				.pad{
					font-size: 34upx;
					color: #4A4034;
				}
				.check {
					height: 50upx;
					line-height: 50upx;
					transform: scale(0.55);
				}
				.check .uni-checkbox-input {
					margin-right: 10upx;
					-webkit-appearance: none;
					appearance: none;
					outline: 0;
					border: 2upx solid #999999;
					background-color: #FFFFFF;
					border-radius: 50%;
					width: 30px;
					height: 30px;
					position: relative;
				}
				.check .uni-checkbox-input.uni-checkbox-input-checked {
					background-color: #FF9900 !important;
					border-color: #FF9900 !important;
					color: #FFFFFF !important;
				}
				
				.check .uni-checkbox-input.uni-checkbox-input-checked:before{
					font-size: 60upx;
				}
			}
			
		}
		
		.bottom_item{
			display: flex;
			justify-content: space-between;
			height: 80upx;
			align-items: center;
			view{
				font-size: 34upx;
				color: #4A4034;
			}
			.money{
				font-size: 64upx !important;
				color: #FF9900;
			}
			.remind{
				font-size: 34upx;
			}
			.activity{
				color: #FF7171;
			}
		}
	
</style>
